#ifndef __DRV_SCA_ARM_H__
#define __DRV_SCA_ARM_H__

#ifdef __cplusplus
extern "C"
{
#endif

#include "main.h"
#include "drv_mrc.h"
#include "drv_SA100.h"
#include "drv_motor_GO_M8010_6.h"
#include "SCA_arm_msg.h"

#pragma pack(1)
    typedef struct SCA_Arm_Com_t
    {
        SCA_ARM_CMD_MSG cmd_msg;
        SCA_ARM_FBK_MSG state_msg;

        uint8_t cmd_correct;
        UART_HandleTypeDef *pc_uart;

    } SCA_Arm_Com_t;

#pragma pack()

#pragma pack(1)
    typedef struct Device_SCA_Arm_t
    {
        const char *name;
        uint8_t id;
        uint8_t mode; // 1 bytes 0x00 init mode, 0x01 position control mode
        uint8_t motor_num;
        SCA_Arm_Com_t com;
        Device_Motor_t motor[3];
        Motor_COM_t motor_com; // 485 communication typedef
        Device_SA100_t SA100;
        Device_MRC_t MRC[2];
        uint8_t HighCMD_Control_Flag;
#ifdef FREERTOS
        SemaphoreHandle_t xArmCmdActionSemaphore;
        SemaphoreHandle_t xArmMotor485IDLESemaphore;
#else
    uint8_t ArmCmdActionSemaphore;
    uint8_t DebugMsgPrintSemaphore;
    uint8_t MotorCmdPusSemaphore;
#endif

        uint8_t ArmActionFlag;

        int32_t excuteNum;
        int32_t losscount_max;
        int32_t getNum;

        float lostrate;

        uint8_t motorID_index;

    } Device_SCA_Arm_t;
#pragma pack()
    void SCA_Arm_Init(const char *dev_name, Device_SCA_Arm_t *dev_SCA_Arm, UART_HandleTypeDef *huart);
    void SCA_Arm_State_Msg_Motify(Device_SCA_Arm_t *dev_SCA_Arm);
    int SCA_Arm_Cmd_Msg_Extract(Device_SCA_Arm_t *dev_SCA_Arm);
    void SCA_Arm_SetZeroPosition(Device_SCA_Arm_t *dev_SCA_Arm);
    void SCA_Arm_MotorControl(Device_SCA_Arm_t *dev_SCA_Arm);
    void SCA_Arm_PositionControl_Cmd_Reaction(Device_SCA_Arm_t *dev_SCA_Arm);
    void SCA_Arm_MotorCommandUpdate(Device_SCA_Arm_t *dev_SCA_Arm);
    void SCA_Arm_ReadCommandMsg(Device_SCA_Arm_t *dev_SCA_Arm);
    void SCA_Arm_SendStateMsg(Device_SCA_Arm_t *dev_SCA_Arm);

    int SCA_Arm_ArmCmdAction(Device_SCA_Arm_t *dev_SCA_Arm);

    extern Device_SCA_Arm_t SCA_Arm_lwb;

#ifdef __cplusplus
}
#endif

#endif
